import Vue from 'vue';
import App from './App';
import router from './router';
import axios from 'axios'
import 'babel-polyfill';
import promise from 'es6-promise';

promise.polyfill();
axios.defaults.baseURL= process.env.NODE_ENV == 'production' ? 'https://gateway.ailive.cloud/' : 'https://test.ailive.cloud/';
// axios.defaults.baseURL= process.env.NODE_ENV == 'prod' ? 'https://app.ailive.cloud/ai-live' : 'https://gateway.ailive.cloud/';
// axios.defaults.baseURL="http://58.56.173.174:8201/ai-live"
axios.defaults.headers.post['Content-Type'] = "application/x-www-form-urlencoded; charset=UTF-8";
axios.defaults.headers['token'] = getCookie("token") || "";
axios.defaults.headers['version'] = "2.2.3";
axios.defaults.headers['client'] = "h5";

// 拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    return response.data;
  }, function (error) {
    // 对响应错误做点什么
    return error;
  });
Vue.prototype.$http = axios;

// 获取token
function getCookie(cname) {
  var name = cname + "=";
  var decodedCookie = decodeURIComponent(document.cookie);
  var ca = decodedCookie.split(';');
  for(var i = 0; i <ca.length; i++) {
      var c = ca[i];
      while (c.charAt(0) == ' ') {
          c = c.substring(1);
      }
      if (c.indexOf(name) == 0) {
          return c.substring(name.length, c.length);
      }
  }
  return "";
};



//引入redirective
import "./modules/directive"
import "./stylesheets/main.scss" //引入全局样式main.scss文件

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
	el: '#app',
	router,
	components: {
		App
	},
	template: '<App/>'
})
